package com.google.code.head2head.dao;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import com.google.code.head2head.model.WebUser;

public class UserDao extends AbstractDao<WebUser> {
	
	private Logger LOG = Logger.getLogger(UserDao.class);

	public Long authenticate(String login, String password) {
		try {
			String sql = "Select Object(u) from WebUser u where username=?1";
			Query q = getEntityManager().createQuery(sql);
			q.setParameter(1, login);
			WebUser u = (WebUser) q.getSingleResult();
			if( u.getPassword().equals(password)){
				return u.getId();
			}
			return null;
		} catch (Exception e) {
			// TODO: handle exception
			return null;
		}
	}

}
